﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LiJu.Record
{
    /// <summary>
    /// 历史记录类型
    /// </summary>
    public enum HistoryRecordType
    {
        /// <summary>
        /// 今天记录
        /// </summary>
        Today,
        /// <summary>
        /// 昨天记录
        /// </summary>
        Yesterday,
        /// <summary>
        /// 近30天记录
        /// </summary>
        Last30Day,
        /// <summary>
        /// 近90天记录
        /// </summary>
        Last90Day,
        /// <summary>
        /// 未知状态
        /// </summary>
        Unknow
    }

    public partial class HistoryRecordButton : UserControl
    {
        /// <summary>
        /// 选中颜色(蓝色)
        /// </summary>
        private static Color selectedColor = Color.FromArgb(0, 149, 255);
        /// <summary>
        /// 未选中颜色
        /// </summary>
        public static Color defaultColor = Color.White;

        public Action<HistoryRecordType> HistoryRecordAction;

        public HistoryRecordType historyRecordType= HistoryRecordType.Unknow;
        public HistoryRecordButton()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 重置状态
        /// </summary>
        public void ResetStatus()
        {
            historyRecordType = HistoryRecordType.Today;
            RefreshButtonBackColor(historyRecordType);
        }

        /// <summary>
        /// 更新按钮选中状态
        /// </summary>
        /// <param name="type"></param>
        private void RefreshButtonBackColor(HistoryRecordType type)
        {
            if(type== HistoryRecordType.Today)
            {
                btn_Today.BackColor = selectedColor;
                btn_Yesterday.BackColor = defaultColor;
                btn_30day.BackColor = defaultColor;
                btn_90day.BackColor = defaultColor;
            }
            else if (type == HistoryRecordType.Yesterday)
            {
                btn_Today.BackColor = defaultColor;
                btn_Yesterday.BackColor = selectedColor;
                btn_30day.BackColor = defaultColor;
                btn_90day.BackColor = defaultColor;
            }
            else if (type == HistoryRecordType.Last30Day)
            {
                btn_Today.BackColor = defaultColor;
                btn_Yesterday.BackColor = defaultColor;
                btn_30day.BackColor = selectedColor;
                btn_90day.BackColor = defaultColor;
            }
            else if (type == HistoryRecordType.Last90Day)
            {
                btn_Today.BackColor = defaultColor;
                btn_Yesterday.BackColor = defaultColor;
                btn_30day.BackColor = defaultColor;
                btn_90day.BackColor = selectedColor;
            }
            else
            {
                btn_Today.BackColor = defaultColor;
                btn_Yesterday.BackColor = defaultColor;
                btn_30day.BackColor = defaultColor;
                btn_90day.BackColor = defaultColor;
            }
        }
        /// <summary>
        /// 初始化HistoryRecordButton
        /// </summary>
        public void InitHistoryRecord()
        {
            RefreshButtonBackColor(HistoryRecordType.Unknow);
        }
        /// <summary>
        /// 查询今天记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Today_Click(object sender, EventArgs e)
        {
            historyRecordType = HistoryRecordType.Today;
            HistoryRecordAction?.Invoke(historyRecordType);
            RefreshButtonBackColor(historyRecordType);
        }
        /// <summary>
        /// 查询昨天记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Yesterday_Click(object sender, EventArgs e)
        {
            historyRecordType = HistoryRecordType.Yesterday;
            HistoryRecordAction?.Invoke(historyRecordType);
            RefreshButtonBackColor(historyRecordType);
        }
        /// <summary>
        /// 查询近30天记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_30day_Click(object sender, EventArgs e)
        {
            historyRecordType = HistoryRecordType.Last30Day;
            HistoryRecordAction?.Invoke(historyRecordType);
            RefreshButtonBackColor(historyRecordType);
        }
        /// <summary>
        /// 查询近90天记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_90day_Click(object sender, EventArgs e)
        {
            historyRecordType = HistoryRecordType.Last90Day;
            HistoryRecordAction?.Invoke(historyRecordType);
            RefreshButtonBackColor(historyRecordType);
        }
    }
}
